home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / src-server / wc_SelectioB.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-04  |  15.1 KB  |  384 lines

  1. /* -*-C-*-
  2. ********************************************************************************
  3. *
  4. * File:         wc_SelectioB.c
  5. * RCS:          $Header: wc_SelectioB.c,v 1.3 91/03/14 03:15:13 mayer Exp $
  6. * Description:  XM_SELECTION_BOX_WIDGET_CLASS
  7. * Author:       Niels Mayer, HPLabs
  8. * Created:      Sat Oct 28 04:41:20 1989
  9. * Modified:     Thu Oct  3 23:41:05 1991 (Niels Mayer) mayer@hplnpm
  10. * Language:     C
  11. * Package:      N/A
  12. * Status:       X11r5 contrib tape release
  13. *
  14. * WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  15. * XLISP version 2.1, Copyright (c) 1989, by David Betz.
  16. *
  17. * Permission to use, copy, modify, distribute, and sell this software and its
  18. * documentation for any purpose is hereby granted without fee, provided that
  19. * the above copyright notice appear in all copies and that both that
  20. * copyright notice and this permission notice appear in supporting
  21. * documentation, and that the name of Hewlett-Packard and David Betz not be
  22. * used in advertising or publicity pertaining to distribution of the software
  23. * without specific, written prior permission.  Hewlett-Packard and David Betz
  24. * make no representations about the suitability of this software for any
  25. * purpose. It is provided "as is" without express or implied warranty.
  26. *
  27. * HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  28. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  29. * IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  30. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  31. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  32. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  33. * PERFORMANCE OF THIS SOFTWARE.
  34. *
  35. * See ./winterp/COPYRIGHT for information on contacting the authors.
  36. * Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  37. * Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  38. *
  39. ********************************************************************************
  40. */
  41. static char rcs_identity[] = "@(#)$Header: wc_SelectioB.c,v 1.3 91/03/14 03:15:13 mayer Exp $";
  42.  
  43. #include <stdio.h>
  44. #include <Xm/Xm.h>
  45. #include <Xm/SelectioB.h>
  46. #include "winterp.h"
  47. #include "user_prefs.h"
  48. #include "xlisp/xlisp.h"
  49. #include "w_funtab.h"
  50. #include "w_XmString.h"
  51.  
  52.  
  53. extern Widget Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(); /* w_classes.c */
  54.  
  55.  
  56. static LVAL k_prompt_dialog;
  57.  
  58. /*****************************************************************************
  59.  * (send XM_SELECTION_BOX_WIDGET_CLASS :new 
  60.  *                           [:managed/:unmanaged]
  61.  *                           [:dialog/:prompt_dialog]
  62.  *                           [<name>]
  63.  *                           <parent> 
  64.  *                           [:XMN_<arg1> <val1>]
  65.  *                           [. . .             ]
  66.  *                           [:XMN_<argN> <valN>])
  67.  *
  68.  * The optional keyword submessage :managed will cause a subsequent call
  69.  * to XtManageChild(). If the submessage :unmanaged is present, or no
  70.  * submessage, then XtManageChild() won't be called, and the resulting
  71.  * widget will be returned unmanaged.
  72.  *
  73.  *   (send XM_SELECTION_BOX_WIDGET_CLASS :new ...)
  74.  *   --> XmCreateSelectionBox();
  75.  *   (send XM_SELECTION_BOX_WIDGET_CLASS :new :dialog ...)
  76.  *   --> XmCreateSelectionDialog();
  77.  *   (send XM_SELECTION_BOX_WIDGET_CLASS :new :prompt_dialog ...)
  78.  *   --> XmCreatePromptDialog();
  79.  ****************************************************************************/
  80. LVAL Xm_Selection_Box_Widget_Class_Method_ISNEW()
  81. {
  82.   extern ArgList Wres_Get_LispArglist(); /* from w_resources.c */
  83.   extern void    Wres_Free_C_Arglist_Data(); /* from w_resources.c */
  84.   extern LVAL k_managed, k_unmanaged, k_dialog;
  85.   LVAL self, o_parent;
  86.   char* name;
  87.   Boolean managed_p;
  88.   LVAL sb_kind;
  89.   Widget widget_id, parent_widget_id;
  90.  
  91.   self = xlgaobject();        /* NOTE: xlobj.c:clnew() returns an OBJECT; if this method
  92.                    returns successfully, it will return a WIDGETOBJ */
  93.   
  94.   /* get optional managed/unmanaged arg */
  95.   if (moreargs() && ((*xlargv == k_managed) || (*xlargv == k_unmanaged)))
  96.     managed_p = (nextarg() == k_managed);
  97.   else
  98.     managed_p = FALSE;        /* by default don't call XtManageChild() */
  99.  
  100.   /* get optional :dialog/:prompt_dialog arg */
  101.   if (moreargs() && ((*xlargv == k_dialog) || (*xlargv ==  k_prompt_dialog)))
  102.     sb_kind = nextarg();
  103.   else
  104.     sb_kind = NIL;        /* default is XmCreateSelectionBox() */
  105.   
  106.   /* get optional <name> arg */
  107.   if (moreargs() && (stringp(*xlargv)))
  108.     name = (char*) getstring(nextarg());
  109.   else
  110.     name = "";            /* default name */
  111.  
  112.   /* get required <parent> widget-object arg */
  113.   parent_widget_id = Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(&o_parent);
  114.  
  115.   /*
  116.    * Store the widget object <self> in the XmNuserData resource on the
  117.    * widget. This will allow us to retrieve the widget object from Xtoolkit
  118.    * functions returning widget ID's without having to keep around a table
  119.    * of widgetID-->widget-objects.
  120.    */
  121.    ARGLIST_RESET(); ARGLIST_ADD(XmNuserData, (XtArgVal) self); 
  122.  
  123.   if (moreargs()) {        /* if there are more arguments, */
  124.     Cardinal xt_numargs;    /* then we have some extra widget resources to set */
  125.     ArgList xt_arglist = Wres_Get_LispArglist(self, parent_widget_id, ARGLIST(), &xt_numargs);
  126.     if (sb_kind == NIL)
  127.       widget_id = XmCreateSelectionBox(parent_widget_id, name, xt_arglist, xt_numargs);
  128.     else if (sb_kind == k_dialog)
  129.       widget_id = XmCreateSelectionDialog(parent_widget_id, name, xt_arglist, xt_numargs);
  130.     else if (sb_kind == k_prompt_dialog)
  131.       widget_id = XmCreatePromptDialog(parent_widget_id, name, xt_arglist, xt_numargs);
  132.     else
  133.       xlfatal("Bug in Xm_Selection_Box_Widget_Class_Method_ISNEW()");
  134.     Wres_Free_C_Arglist_Data();
  135.   }
  136.   else
  137.     if (sb_kind == NIL)
  138.       widget_id = XmCreateSelectionBox(parent_widget_id, name, ARGLIST());
  139.     else if (sb_kind == k_dialog)
  140.       widget_id = XmCreateSelectionDialog(parent_widget_id, name, ARGLIST());
  141.     else if (sb_kind == k_prompt_dialog)
  142.       widget_id = XmCreatePromptDialog(parent_widget_id, name, ARGLIST());
  143.     else
  144.       xlfatal("Bug in Xm_Selection_Box_Widget_Class_Method_ISNEW()");
  145.  
  146.   Wcls_Initialize_WIDGETOBJ(self, widget_id);
  147.  
  148.   if (managed_p)
  149.     XtManageChild(widget_id);
  150.   
  151. #ifdef DEBUG_WINTERP_1
  152.   Wcls_Print_WidgetObj_Info(self);
  153. #endif
  154.   return (self);
  155. }
  156.  
  157.  
  158. /******************************************************************************
  159.  * typedef struct
  160.  * {
  161.  *     int reason;
  162.  *     XEvent    *event;
  163.  *     XmString    value;
  164.  *     int    length;
  165.  * } XmSelectionBoxCallbackStruct;
  166.  ******************************************************************************/
  167. static void Lexical_Bindings_For_XmSelectionBoxCallbackStruct(bindings_list, lexical_env, cd, o_widget)
  168.      LVAL bindings_list;    /* a list of symbols to which values from XmSelectionBoxCallbackStruct are bound */
  169.      LVAL lexical_env;        
  170.      XmSelectionBoxCallbackStruct* cd;
  171.      LVAL o_widget;        /* XLTYPE_WIDGETOBJ */
  172. {
  173.   extern LVAL s_CALLBACK_WIDGET, s_CALLBACK_REASON, s_CALLBACK_XEVENT, s_CALLBACK_VALUE, s_CALLBACK_LENGTH; /* w_callbacks.c */
  174.   extern LVAL Wcb_Get_Callback_Reason_Symbol();    /* w_callbacks.c */
  175.   register LVAL s_bindname;
  176.  
  177.   for ( ; consp(bindings_list); bindings_list = cdr(bindings_list)) {
  178.  
  179.     s_bindname = car(bindings_list);
  180.  
  181.     if (s_bindname == s_CALLBACK_WIDGET) {
  182.       xlpbind(s_bindname, o_widget, lexical_env);
  183.     }
  184.     else if (s_bindname == s_CALLBACK_REASON) {
  185.       xlpbind(s_bindname, Wcb_Get_Callback_Reason_Symbol(cd->reason), lexical_env);
  186.     }
  187.     else if (s_bindname == s_CALLBACK_XEVENT) {
  188.       xlpbind(s_bindname, (cd->event) ? cv_xevent(cd->event) : NIL, lexical_env);
  189.     }
  190.     else if (s_bindname == s_CALLBACK_VALUE) {
  191.       xlpbind(s_bindname, (cd->value) ? cv_xmstring(XmStringCopy(cd->value)) : NIL, lexical_env); /* copy the XmString even though cd->value never looks like it gets freed -- it's inconsistant w/ other callback XmStrings.. maybe it'll get fixed eventually */
  192.     }
  193.     else if (s_bindname == s_CALLBACK_LENGTH) {
  194.       xlpbind(s_bindname, cvfixnum((FIXTYPE) cd->length), lexical_env);
  195.     }
  196.     else {
  197.       extern char temptext[];    /* from winterp.c */
  198.       sprintf(temptext,
  199.           "Unknown binding name in XmSelectionBoxCallbackStruct callback evaluator. Valid symbols are [%s %s %s %s %s].",
  200.           (char*) getstring(getpname(s_CALLBACK_WIDGET)),
  201.           (char*) getstring(getpname(s_CALLBACK_REASON)),
  202.           (char*) getstring(getpname(s_CALLBACK_XEVENT)),
  203.           (char*) getstring(getpname(s_CALLBACK_VALUE)),
  204.           (char*) getstring(getpname(s_CALLBACK_LENGTH)));
  205.       xlerror(temptext, s_bindname);
  206.     }
  207.   }
  208. }
  209.  
  210.  
  211. /******************************************************************************
  212.  * This is called indirectly via XtAddCallback() for callbacks returning
  213.  * an XmSelectionBoxCallbackStruct as call_data.
  214.  ******************************************************************************/
  215. static void XmSelectionBoxCallbackStruct_Callbackproc(widget, client_data, call_data)
  216.      Widget    widget;
  217.      XtPointer client_data;
  218.      XtPointer call_data;
  219. {
  220.   extern void Wcb_Meta_Callbackproc(); /* w_callbacks.c */
  221.  
  222.   Wcb_Meta_Callbackproc(client_data, call_data,
  223.             Lexical_Bindings_For_XmSelectionBoxCallbackStruct,
  224.             NULL);
  225. }
  226.  
  227.  
  228. /******************************************************************************
  229.  * Same as WIDGET_CLASS's :add_callback method except that this understands
  230.  * how to get values from the XmSelectionBoxCallbackStruct.
  231.  * Specifying one or more of the following symbols in the callback bindings 
  232.  * list will bind that symbol's value in the lexical environment of the callback:
  233.  * CALLBACK_WIDGET
  234.  * CALLBACK_REASON
  235.  * CALLBACK_XEVENT
  236.  * CALLBACK_VALUE
  237.  * CALLBACK_LENGTH
  238.  ******************************************************************************/
  239. LVAL Xm_Selection_Box_Widget_Class_Method_ADD_CALLBACK()
  240. {
  241.   extern LVAL Wcb_Meta_Method_Add_Callback(); /* w_callbacks.c */
  242.  
  243.   return (Wcb_Meta_Method_Add_Callback(XmSelectionBoxCallbackStruct_Callbackproc, FALSE));
  244. }
  245.  
  246.  
  247. /******************************************************************************
  248.  * Same as WIDGET_CLASS's :set_callback method except that this understands
  249.  * how to get values from the XmSelectionBoxCallbackStruct.
  250.  * Specifying one or more of the following symbols in the callback bindings 
  251.  * list will bind that symbol's value in the lexical environment of the callback:
  252.  * CALLBACK_WIDGET
  253.  * CALLBACK_REASON
  254.  * CALLBACK_XEVENT
  255.  * CALLBACK_VALUE
  256.  * CALLBACK_LENGTH
  257.  ******************************************************************************/
  258. LVAL Xm_Selection_Box_Widget_Class_Method_SET_CALLBACK()
  259. {
  260.   extern LVAL Wcb_Meta_Method_Add_Callback(); /* w_callbacks.c */
  261.  
  262.   return (Wcb_Meta_Method_Add_Callback(XmSelectionBoxCallbackStruct_Callbackproc, TRUE));
  263. }
  264.  
  265.  
  266. /******************************************************************************
  267.  * (send <selectionbox_widget> :get_child <childname>)
  268.  * ==> returns the WIDGETOBJ correspomding to <childname> which can be one
  269.  * of the following:
  270.  * :DIALOG_LIST, :DIALOG_LIST_LABEL, :DIALOG_SELECTION_LABEL, :DIALOG_WORK_AREA
  271.  * :DIALOG_TEXT, :DIALOG_SEPARATOR, :DIALOG_OK_BUTTON, :DIALOG_APPLY_BUTTON,
  272.  * :DIALOG_CANCEL_BUTTON, :DIALOG_HELP_BUTTON, :DIALOG_DEFAULT_BUTTON
  273.  *
  274.  * Widget XmSelectionBoxGetChild (sb, which)
  275.  *        Widget sb;
  276.  *        int which;
  277.  ******************************************************************************/
  278. LVAL Xm_Selection_Box_Widget_Class_Method_GET_CHILD()
  279. {
  280.   LVAL self, lval_child;
  281.   Widget widget_id;
  282.   int child;
  283.   extern LVAL Wcls_WidgetID_To_WIDGETOBJ();
  284.   extern LVAL s_XmDIALOG_LIST, s_XmDIALOG_LIST_LABEL, s_XmDIALOG_SELECTION_LABEL,
  285.   s_XmDIALOG_WORK_AREA, s_XmDIALOG_TEXT, s_XmDIALOG_SEPARATOR,
  286.   s_XmDIALOG_OK_BUTTON, s_XmDIALOG_APPLY_BUTTON, s_XmDIALOG_CANCEL_BUTTON,
  287.   s_XmDIALOG_HELP_BUTTON, s_XmDIALOG_DEFAULT_BUTTON; /* from w_resources.c */
  288.   
  289.   widget_id = Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(&self);
  290.   lval_child = xlgasymbol();
  291.   xllastarg();
  292.  
  293.   if (lval_child == s_XmDIALOG_LIST)
  294.     child = XmDIALOG_LIST;
  295.   else if (lval_child == s_XmDIALOG_LIST_LABEL)
  296.     child = XmDIALOG_LIST_LABEL;
  297.   else if (lval_child == s_XmDIALOG_SELECTION_LABEL)
  298.     child = XmDIALOG_SELECTION_LABEL;
  299.   else if (lval_child == s_XmDIALOG_WORK_AREA)
  300.     child = XmDIALOG_WORK_AREA;
  301.   else if (lval_child == s_XmDIALOG_TEXT)
  302.     child = XmDIALOG_TEXT;
  303.   else if (lval_child == s_XmDIALOG_SEPARATOR)
  304.     child = XmDIALOG_SEPARATOR;
  305.   else if (lval_child == s_XmDIALOG_OK_BUTTON)
  306.     child = XmDIALOG_OK_BUTTON;
  307.   else if (lval_child == s_XmDIALOG_APPLY_BUTTON)
  308.     child = XmDIALOG_APPLY_BUTTON;
  309.   else if (lval_child == s_XmDIALOG_CANCEL_BUTTON)
  310.     child = XmDIALOG_CANCEL_BUTTON; 
  311.   else if (lval_child == s_XmDIALOG_HELP_BUTTON)
  312.     child = XmDIALOG_HELP_BUTTON;
  313.   else if (lval_child == s_XmDIALOG_DEFAULT_BUTTON)
  314.     child =XmDIALOG_DEFAULT_BUTTON;
  315.   else
  316.     xlerror("Invalid selectionbox child symbol.", lval_child);
  317.     
  318.   return (Wcls_WidgetID_To_WIDGETOBJ(XmSelectionBoxGetChild(widget_id, child)));
  319. }
  320.  
  321.  
  322. /******************************************************************************
  323.  * (send <selectionbox_widget> :GET_LIST_ITEMS)
  324.  *     ==> returns an array of XmStrings.
  325.  *
  326.  * This retrieves the XmSelectionBox widget resources XmNlistItems and
  327.  * XmNlistItemCount from <selectionbox_widget> and returns an array of
  328.  * XmStrings representing the items in the selectionbox's list.
  329.  *******************************************************************************/
  330. LVAL Xm_Selection_Box_Widget_Class_Method_GET_LIST_ITEMS()
  331. {
  332.   LVAL self;
  333.   Widget widget_id;
  334.   XmStringTable xmstrtab;
  335.   int        xmstrtab_size;
  336.  
  337.   widget_id = Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(&self);
  338.   xllastarg();
  339.  
  340.   ARGLIST_RESET();
  341.   ARGLIST_ADD(XmNlistItems, &xmstrtab);
  342.   ARGLIST_ADD(XmNlistItemCount, &xmstrtab_size);
  343.   XtGetValues(widget_id, ARGLIST());
  344.  
  345.   return (Wxms_XmStringTable_To_Lisp_Vector(xmstrtab, xmstrtab_size));
  346. }
  347.  
  348.  
  349. /******************************************************************************
  350.  *
  351.  ******************************************************************************/
  352. Wc_SelectioB_Init()
  353. {
  354.   LVAL o_XM_SELECTION_BOX_WIDGET_CLASS;
  355.   extern LVAL Wcls_Create_Subclass_Of_WIDGET_CLASS(); /* w_classes.c */
  356.   extern      xladdmsg();    /* from xlobj.c */
  357.  
  358.   k_prompt_dialog      = xlenter(":PROMPT_DIALOG");
  359.  
  360.   o_XM_SELECTION_BOX_WIDGET_CLASS =
  361.     Wcls_Create_Subclass_Of_WIDGET_CLASS("XM_SELECTION_BOX_WIDGET_CLASS",
  362.                      xmSelectionBoxWidgetClass);
  363.  
  364.   /* a special :isnew method on this class allows for the creation of this
  365.      widget inside a popup shell if one of the following submessage keywords
  366.      are given: 
  367.      :dialog, :prompt_dialog */
  368.   xladdmsg(o_XM_SELECTION_BOX_WIDGET_CLASS, ":ISNEW", 
  369.        FTAB_Xm_Selection_Box_Widget_Class_Method_ISNEW);
  370.  
  371.   xladdmsg(o_XM_SELECTION_BOX_WIDGET_CLASS, ":ADD_CALLBACK",
  372.            FTAB_Xm_Selection_Box_Widget_Class_Method_ADD_CALLBACK);
  373.  
  374.   xladdmsg(o_XM_SELECTION_BOX_WIDGET_CLASS, ":SET_CALLBACK",
  375.            FTAB_Xm_Selection_Box_Widget_Class_Method_SET_CALLBACK);
  376.  
  377.   xladdmsg(o_XM_SELECTION_BOX_WIDGET_CLASS, ":GET_CHILD",
  378.            FTAB_Xm_Selection_Box_Widget_Class_Method_GET_CHILD);
  379.  
  380.   xladdmsg(o_XM_SELECTION_BOX_WIDGET_CLASS, ":GET_LIST_ITEMS",
  381.            FTAB_Xm_Selection_Box_Widget_Class_Method_GET_LIST_ITEMS);
  382. }
  383.